<template>
  <div id="target">
    <el-table
      v-if="noResponse"
      v-loading="loading"
      style="width: 100%;height: 410px;margin: 10px auto;z-index: 1">
    </el-table>
    <div  v-if="isEmpty" style="width: 800px; height: 410px; background-color: rgba(255,255,255,0.9);margin-top: 10px">
      <el-empty :image-size="200"></el-empty>
    </div>
    <div>
      <div class="cards" v-if="!isSearch && !isEmpty" v-for="(item,index) in contentData" :key="index">
      <div v-if="index==0">
        <div class="topping"></div>
        <div class="top-text">{{$t('userHome.error.setTop')}}</div>
      </div>
      <router-link target="_blank" :to="{path:'/worksDisplayPage',query:{workId:item.errorId}}">
        <div class="cards-top">
          <div class="cards-top-title">
            <strong>{{item.title}}</strong>
          </div>
          <div class="cards-top-content">
            {{item.errorDescribe}}
          </div>
        </div>
      </router-link>
      <div class="cards-bottom">
        <div class="cards-bottom-pubTime"><i class="iconfont icon-shijian cards-bottom-icn" style="color: rgba(108,106,109,0.8)"></i>{{item.publishTime}}</div>
        <div class="cards-bottom-act"><i class="iconfont icon-huoyue cards-bottom-icn" style="font-size: 20px; color: rgb(230, 146, 22);"></i>{{item.act}}</div>
        <div class="cards-bottom-star"><i class="iconfont icon-star cards-bottom-icn" style="font-size: 22px;color: rgb(209, 80, 57);"></i>{{item.star}}</div>
        <div class="cards-bottom-classify"><i class="iconfont icon-leibie cards-bottom-icn" style="font-size: 16px; color: rgb(71, 63, 192);"></i>{{item.label}}</div>
      </div>
    </div>
      <div class="cards" v-if="isSearch && !isEmpty" v-for="(item,index) in contentData" :key="index">
        <router-link target="_blank" :to="{path:'/worksDisplayPage',query:{workId:item.articleId}}">
          <div class="cards-top">
            <div class="cards-top-title">
              <strong v-html="item.title"></strong>
            </div>
            <div class="cards-top-content">
              {{item.titleDescribe}}
            </div>
          </div>
        </router-link>
        <div class="cards-bottom">
          <div class="cards-bottom-pubTime"><i class="iconfont icon-shijian cards-bottom-icn" style="color: rgba(108,106,109,0.8)"></i>{{item.date}}</div>
          <div class="cards-bottom-act"><i class="iconfont icon-huoyue cards-bottom-icn" style="font-size: 20px; color: rgb(230, 146, 22);"></i>{{item.act}}</div>
          <div class="cards-bottom-star"><i class="iconfont icon-star cards-bottom-icn" style="font-size: 22px;color: rgb(209, 80, 57);"></i>{{item.star}}</div>
          <div class="cards-bottom-classify"><i class="iconfont icon-leibie cards-bottom-icn" style="font-size: 16px; color: rgb(71, 63, 192);"></i>{{item.label}}</div>
        </div>
      </div>
      <el-pagination
        v-if="!isEmpty && !noResponse"
        background
        layout="prev, pager, next"
        :total=pageTotal
        @current-change="handleCurrentChange(currentPage)"
        :current-page.sync = currentPage
        class="page">
      </el-pagination>
    </div>
  </div>
</template>

<script>
    export default {
        name: "UserArticleCard-error",
        data(){
            return{
                loading:"true",
                isEmpty:false,
                noResponse: true,
                baseURL:'http://localhost:8081/userHomePage/error/query/',
                baseURL2:'http://localhost:8081/userHomePage/getPage/error/',
                baseURL3:'http://localhost:8081/search/userWork/error/',
                baseURL4:'http://localhost:8081/search/getHomePageWorkPages/error/',
                contentData:'',
                pageTotal:0,
                currentPage:1,  // 当前页

                isSearch:'',
                keyWord:'',
                UID:'',
            }
        },
        mounted() {
            this.$emit("component","error")
            this.getWorksInfo()
            // this.getPages()
        },
        methods:{
            searchInfo(keyWord, UID){
                this.keyWord = keyWord
                this.UID = UID
                this.axios.post(this.baseURL3 + keyWord +"/"+ UID +"/"+ 1).then(res=>{
                    this.isSearch = true
                    this.noResponse=false
                    if (res.data == false){
                        this.$message.error(this.$t('userHome.error.serviceUnusual'))
                    } else if (res.data == "empty") {
                        this.isEmpty = true
                        this.contentData = ""
                    } else {
                        this.isEmpty = false
                        this.contentData = res.data
                    }
                }).catch(
                    exception=>{
                        console.log(exception)
                    }
                )
                this.searchInfoPages(keyWord,UID)
            },
            searchInfoPages(keyWord,UID){
                this.axios.post(this.baseURL4 + keyWord +"/"+ UID).then(res=>{
                    this.pageTotal = res.data * 10
                }).catch(
                    exception=>{
                        console.log(exception)
                    }
                )
            },
            getWorksInfo(){
                this.axios.post(this.baseURL + this.$route.query.userId + "/1").then(res=>{
                    this.isSearch = false
                    this.noResponse=false
                    if (res.data == false){
                        this.$message.error(this.$t('userHome.error.serviceUnusual'))
                    } else if (res.data == "empty") {
                        this.isEmpty = true
                    } else {
                        this.contentData = res.data
                        this.isEmpty = false
                    }
                }).catch(
                    exception=>{
                        console.log(exception)
                    }
                )
                this.getPages()
            },
            getPages(){
                this.axios.post(this.baseURL2+this.$route.query.userId).then(res=>{
                    this.pageTotal = res.data * 10
                }).catch(
                    exception=>{
                        console.log(exception)
                    }
                )
            },
            handleCurrentChange(currentPage){
                if (this.isSearch){
                    this.axios.post(this.baseURL3 + this.keyWord +"/"+ this.UID +"/"+ currentPage).then(res=>{
                        // this.isSearch = true
                        this.noResponse=false
                        if (res.data == false){
                            this.$message.error(this.$t('userHome.error.serviceUnusual'))
                        } else if (res.data == "empty") {
                            this.isEmpty = true
                            this.contentData = ""
                        } else {
                            this.isEmpty = false
                            this.contentData = res.data
                        }
                    }).catch(
                        exception=>{
                            console.log(exception)
                        }
                    )
                } else {
                    this.axios.post(this.baseURL+this.$route.query.userId+"/"+currentPage).then(res=>{
                        this.noResponse=false
                        if (res.data != "empty"){
                            this.contentData = res.data
                            let target = document.getElementById("target").offsetTop
                            window.scrollTo({
                                top:target,
                                behavior: "smooth"
                            });
                        }
                    }).catch(
                        exception=>{
                            console.log(exception)
                        }
                    )
                }
            },
        }
    }
</script>

<style scoped>
  .quxiaozhiding,.zhiding{
    color: rgb(134,131,129);
  }
  .quxiaozhiding:hover,.zhiding:hover{
    color: #343434;
  }
  .cards{
    margin: 0px auto;
    width: 800px;
    height: 120px;
    border: solid 1px rgb(224, 224, 224);
    background-color: rgba(255, 255, 255,0.9);
    /*background-color: white;*/
    border-radius: 3px;
    margin-top: 10px;
    transition: 0.3s;
    position: relative;
    letter-spacing: 1px;
  }
  .topping{
    position: absolute;
    top: -33px;
    right: -33px;
    width: 30px;
    height: 30px;
    border: transparent solid 18px;
    border-bottom: rgb(255, 76, 76) solid 18px;
    transform: rotate(45deg);
  }
  .top-text{
    position: absolute;
    top: 10px;
    right: 6px;
    width: 30px;
    height: 30px;
    font-size: 10px;
    color: rgb(243, 243, 243);
    transform: rotate(45deg);
  }
  .cards:hover{
    box-shadow: 0 0 5px rgb(173, 173, 173);
    transform:translateY(-2px);
  }
  .cards-top{
    width: 100%;
    height: 65%;
    /* position: relative; */
  }
  .cards-top-title{
    height: 50%;
    line-height: 40px;
    padding-left: 20px;
    padding-right: 45px;
    font-size: 15px;
    font-weight: bolder;
    color: rgb(0, 39, 71);
    /* 文字溢出处理 */
    display: -webkit-box;
    overflow:hidden;
    text-overflow: ellipsis;
    -webkit-box-orient:vertical;
    -webkit-line-clamp:1;
  }
  /*.topping{*/
  /*  position: absolute;*/
  /*  top: -33px;*/
  /*  right: -33px;*/
  /*  width: 30px;*/
  /*  height: 30px;*/
  /*  border: transparent solid 18px;*/
  /*  border-bottom: rgb(255, 76, 76) solid 18px;*/
  /*  transform: rotate(45deg);*/
  /*}*/
  /*.top-text{*/
  /*  position: absolute;*/
  /*  top: 8px;*/
  /*  right: 4px;*/
  /*  width: 30px;*/
  /*  height: 30px;*/
  /*  font-size: 10px;*/
  /*  color: rgb(243, 243, 243);*/
  /*  transform: rotate(45deg);*/
  /*}*/
  .cards-top-content{
    padding-left: 20px;
    padding-right: 40px;
    font-size: 5px;
    color: rgb(131, 131, 131);
    line-height: 16px;
    /* 文字溢出处理 */
    display: -webkit-box;
    overflow:hidden;
    text-overflow: ellipsis;
    -webkit-box-orient:vertical;
    -webkit-line-clamp:2;
  }
  .cards-bottom div{
    float: left;
    height: 40px;
    color: rgb(100, 100, 100);
  }
  .cards-bottom-headPho{
    width: 190px;
  }
  .cards-bottom-headPho div:nth-child(1){
    width: 20px;
    height: 20px;
    margin-top: 8px;
    margin-left: 20px;
  }
  .cards-bottom-headPho div:nth-child(2){
    height: 20px;
    width: 110px;
    margin-left: 5px;
    margin-top: 8px;
    line-height: 20px;
    font-size: 10px;
    /* 文字溢出处理 */
    display: -webkit-box;
    overflow:hidden;
    text-overflow: ellipsis;
    -webkit-box-orient:vertical;
    -webkit-line-clamp:1;
  }
  .cards-bottom-pubTime{
    width: 200px;
    line-height: 36px;
    font-size: 11px;
    margin-left: 180px;
  }
  .cards-bottom-act{
    width: 100px;
    line-height: 35px;
    font-size: 11px;
  }
  .cards-bottom-star{
    width: 100px;
    line-height: 35px;
    font-size: 11px;
  }
  .cards-bottom-classify{
    width: 200px;
    line-height: 35px;
    font-size: 11px;
    /* 文字溢出处理 */
    display: -webkit-box;
    overflow:hidden;
    text-overflow: ellipsis;
    -webkit-box-orient:vertical;
    -webkit-line-clamp:1;
     /*background-color: tomato;*/
  }
  .cards-bottom-notZhiding,.cards-bottom-zhiding{
    width: 35px;
    line-height: 35px;
    font-size: 11px;
    /*background-color: #66b2aa;*/
  }
  .cards-bottom-icn{
    margin-right: 5px;
  }
  .page{
    margin: 10px auto;
    margin-left: -10px;
  }
</style>
